package top.infopub.mgr.sys.web;

import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import top.infopub.mgr.common.page.ParamPage;
import top.infopub.mgr.common.vo.RspVo;
import top.infopub.mgr.sys.service.HolidaysService;
import top.infopub.mgr.sys.vo.HolidaysVo;
import top.infopub.model.sys.Holidays;

import com.github.pagehelper.Page;

/**
 * 节日管理
 * @author Hunter
 * @version 1.0
 */
@Controller
@RequestMapping("/holiday")
public class HolidayController {
    
    @Autowired
    HolidaysService holidayService;
    
    
    @RequestMapping("/list")
    public String list() {
        return "sys/layholiday-list";
    }
    
    /**
     * 充值记录分页列表数据
     * @param 
     * @return
     */
    @RequestMapping("/queryDataByCondition")
    public @ResponseBody RspVo<Holidays> queryDataByCondition(HolidaysVo holidaysVo,
            ParamPage paramPage) {
        Page<Holidays> page = new Page<Holidays>();
        page.setPageNum(paramPage.getPage());
        page.setPageSize(paramPage.getLimit());
        if (holidaysVo.getEndDate() != null) {
            holidaysVo.setEndDate(DateUtils.addDays(holidaysVo.getEndDate(), 1));
        }
        page = holidayService.selectPageByVo(page, holidaysVo);
        return RspVo.getSuccessResponse(page.getTotal(), page.getResult());
    }
    
    /**
     * 初始化节假日
     * @param year 年份
     * @return 
     * @see
     */
    @RequestMapping("/init")
    public @ResponseBody RspVo<String> initFestivalDay(String year) {
        holidayService.initFestivalDay(year);
        return RspVo.getSuccessResponse();
    }
    
    /**
     * 设置为工作日
     * @param id 主键Id
     * @return 
     * @see
     */
    @RequestMapping("/setWork")
    public @ResponseBody RspVo<String> setWork(String id) {
        holidayService.setWork(id);
        return RspVo.getSuccessResponse();
    }
    
    /**
     * 设置为休息日
     * @param id 主键Id
     * @return 
     * @see
     */
    @RequestMapping("/setRest")
    public @ResponseBody RspVo<String> setRest(String id) {
        holidayService.setRest(id);
        return RspVo.getSuccessResponse();
    }

}
